//
//  NRWCarMineController.m
//  New_Runway
//
//  Created by mack on 2018/1/24.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "NRWCarMineController.h"

#import "MineMessageCell.h"
#import "CarSetListCell.h"
#import "CompanyMessageVC.h"
#import "WorkDeskMainModel.h"



@interface NRWCarMineController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) NSMutableArray *sectionArray;

@end

@implementation NRWCarMineController
-(NSMutableArray *)sectionArray{
    if (!_sectionArray) {
        _sectionArray = [[NSMutableArray alloc] init];
    }
    return _sectionArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBarView.titleLabel.text = @"我的";
    self.navigationBarView.leftItem.hidden = YES;
    for (NSDictionary *dic in _loginModel.resourceList) {
        WorkDeskMainModel *sectionModel = [WorkDeskMainModel mj_objectWithKeyValues:dic];
        [self.sectionArray addObject:sectionModel];
        
    }
    [self initTableview];
 
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
}
-(void)initTableview{
    kSelfWeak;
    self.tableview = [[UITableView alloc] init];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    _tableview.estimatedRowHeight = 0;
    _tableview.estimatedSectionHeaderHeight = 0;
    _tableview.estimatedSectionFooterHeight = 0;
    if (@available(iOS 11.0, *)) {
        self.tableview.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = false;
    }
    self.tableview.backgroundColor = UIColorHex(0xf5f5f5);
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableview registerClass:[CarSetListCell class] forCellReuseIdentifier:@"CarSetListCell"];
    [self.tableview registerNib:[UINib nibWithNibName:@"MineMessageCell" bundle:nil] forCellReuseIdentifier:@"MineMessageCell"];
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).mas_equalTo(self.navH );
        make.bottom.equalTo(weakSelf.view).mas_equalTo(-self.tabH);
        make.left.right.equalTo(weakSelf.view);
    }];
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 120;
    }
   
    return 50;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.sectionArray.count + 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        
        MineMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineMessageCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.name.text = [NRWCarUser sharedUser].userName;
        cell.phoneNem.text = [NRWCarUser sharedUser].userMobile;
        cell.shopName.text = [NRWCarUser sharedUser].shopName;
        return cell;
    }else{
            WorkDeskMainModel *sectiomModel = self.sectionArray[indexPath.row - 1];
            CarSetListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CarSetListCell"];
            cell.layer.masksToBounds = YES;
            cell.switchButton.hidden = YES;
            cell.centerTF.hidden = YES;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.label.text = sectiomModel.resourceName;
            return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
 
    if (indexPath.row == 0) {
        CompanyMessageVC *comVc = [[CompanyMessageVC alloc] init];
        kSelfWeak;
        comVc.success = ^{
            [weakSelf.tableview reloadData];
        };
        [self.navigationController pushViewController:comVc animated:YES];
    }else{
        WorkDeskMainModel *sectiomModel = self.sectionArray[indexPath.row - 1];
        [[CTMediator sharedInstance] Router_viewControllerForMine:@{@"vc":sectiomModel.resourceRemark} callback:^(NSDictionary *info) {
            
        }];
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    
}
@end
